package cn.zx.rmq.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @Package: cn.zx.rmq.producer
 * @ClassName: SpringbootProducer
 * @Author: Think
 * @CreateTime: 2021/6/30 10:46
 * @Description:
 */
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class SpringbootProducer {

    @Autowired
    private DefaultMQProducer defaultMQProducer;

    @Test
    public void send() throws MQBrokerException, RemotingException, InterruptedException, MQClientException {
        String msg = "客户充值1000元！！！";
        log.info("开始发送消息："+msg);
        Message sendMsg = new Message("KYC","about-money",msg.getBytes());
        //默认3秒超时
        SendResult sendResult = defaultMQProducer.send(sendMsg);
        log.info("消息发送响应信息："+sendResult.toString());
    }
}
